package com.weilive.core.utils;

import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;

import au.com.bytecode.opencsv.CSVWriter;

public class CSVUtils {

	public static class Writer {
//		 private PrintWriter writer;
		 private CSVWriter writer;
		
		public Writer(String file) throws Exception {
//	        byte[] bom = new byte[] { (byte)0xEF, (byte)0xBB, (byte)0xBF }; 
//	        writer = new PrintWriter(file, "UTF-8");
//	        writer.write(new String(bom));
			
			OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file), Charset.forName("UTF-8")); 
//			out.write(new String(bom));
			writer = new CSVWriter(out, ',');
		}
		
		public void println(String...args) throws Exception {
//			for (int i = 0; i < args.length; i ++) {
//				args[i] = new String(args[i].getBytes(), Charset.forName("GBK"));
//			}
			writer.writeNext(args);
//			for (int i = 0; i < args.length; i++) {
//				writer.write(args[i]);
//				if (i != args.length - 1) {
//					writer.write(",");
//				} else {
//					writer.println();
//				}
//			}
		}
		
		public void close() throws Exception {
			writer.close();
		}
	}
}
